//
//  RepayScheduleListViewModel.swift
//  cxd4iphone
//
//  Created by hexy on 12/22/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit
import ReactiveCocoa

class RepayPlanListViewModel: BaseTableListViewModel {

//    override init() {
//        
//        super.init()
//        
//        let vm1 = RepayPlanCellViewModel()
//        
//        self.sections = [[vm1, vm1, vm1, vm1, vm1, vm1, vm1, vm1]]
//    }
    
    func loadRepayPlanList(loanId: String) -> RACSignal {
        
        return RACSignal.createSignal({ (subscriber) -> RACDisposable! in
            
            APIManager.loadRepayPlanList(loanId).subscribeNext({ (result) -> Void in
                
//                xx_JsonPrint(dict: result)
                let array = result as! [[String: AnyObject]]
                
                var arrM = [RepayPlanCellViewModel]()
                for dict in array {
                    
                    arrM.append(RepayPlanCellViewModel(repayPlanModel: RepayPlanModel(dict: dict)))
                }
                
                self.sections = [arrM]
                subscriber.sendCompleted()
                
                }, error: { (error) -> Void in
                    
                    subscriber.sendError(error)
            })
            
            return RACDisposable(block: {})
        })
    }

}
